package model;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.Consumer;

/**
 * Created by admin
 * <p>
 * Date :2020/10/14
 * <p>
 * Description : 游戏裁判
 * <p>
 * Version :1.0
 */
public class Referee {
    private static final Logger logger = LoggerFactory.getLogger(Referee.class);

    /**
     * 洗牌
     *
     * @param pocker
     * @return
     * @throws Exception
     */
    public Referee shufflePocker(Pocker pocker) throws Exception {
        if (pocker.isValid()) {
            pocker.shuffle();
        } else {
            throw new Exception("扑克牌不合法");
        }
        return this;
    }


    /**
     * 发牌
     * @param pocker 当前扑克牌
     * @param count 需要发出的数量
     * @param consumer 接受方
     */
    public void castPocker(Pocker pocker, int count, Consumer<PockerCard> consumer) {
        for (int i = 0; i < count; i++) {
            consumer.accept(pocker.pop());
        }

    }

    /**
     * 判定玩家输赢
     * @param master
     * @param next
     * @return
     */
    public boolean judge(PockerPlayer master, PockerPlayer next) {
        GoldenFlower masterGoldenFlower = master.getGoldenFlower();
        GoldenFlower anotherGoldenFlower = next.getGoldenFlower();
        return masterGoldenFlower.compareTo(anotherGoldenFlower) > 0;
    }
}
